<?php
namespace app\model;

use think\Model;

class Admin extends Model
{
    const IS_DELETE_NO = 0; //没删除

    /**
     * @Description 判断用户名称是否存在
     * @author: zj
     * @param string $name
     * @time 2024/03/07 17:20:05
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkNameIsExist(string $name)
    {
        $info = $this->field('id')
            ->where('username', $name)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();
        
        if (!$info) {
            return false;
        }

        return $info['id'];
    }

    /**
     * @Description 判断手机号是否存在
     * @author: zj
     * @param string $phone
     * @time 2024/03/07 17:20:16
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkPhoneIsExist(string $phone)
    {
        $info = $this->field('id')
            ->where('phone', $phone)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();
        
        if (!$info) {
            return false;
        }

        return $info['id'];
    }

    /**
     * @Description 判断用户是否存在
     * @author: zj
     * @param int $adminId
     * @time 2024/03/07 17:20:26
     * @return false|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function checkExistById(int $adminId)
    {
        $info = $this->field('id') 
            ->where('id', $adminId)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return false;
        }

        return $info['id'];
    }
}